#ifndef __HTTPLIB__
# define __HTTPLIB__

#if defined(WIN32)
# define _WIN32_WINNT 0x0501
#endif

#include "boost/asio.hpp"
#include "httpResponse.h"

#define ENDL "\r\n"

class HttpLib
{

public:

    HttpLib();
    ~HttpLib();

    bool                            httpConnection(const std::string&, const std::string& port = "80");
    bool                            setAuth(const std::string&);

    bool                            request(const std::string&, const std::string&, std::map<std::string, std::string>* args = NULL);
    HttpResponse*                   getRequest() const;

    void                            close();

private:

    void                            send(const std::string&);
    void                            receive(void);

    const std::string               urlEncode(const std::map<std::string, std::string>&);
    const std::list<std::string>    getHostByName(const std::string& name, const std::string& port = "80") const;
    const std::string               Base64_encode(const std::string & data);

    boost::asio::io_service*        _ios;
    boost::asio::ip::tcp::socket*   _socket;
    std::string                     _host;
    std::string                     _login;
    std::string                     _pass;
    std::string                     _auth64;
    HttpResponse*                   _response;

};

#endif
